package com.hm.ibsm.service;

import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.TypeReference;
import com.hm.common.network.httpclient.HttpClientFactory;
import com.hm.common.network.httpclient.HttpClientResponseParse;
import com.hm.common.su.ServerResponseParse;
import com.hm.common.su.bean.PageInfo;
import com.hm.common.su.bean.ServerResponse;
import com.hm.ibsm.manage.vo.user.UserVo;
import com.hm.ibsm.util.LocationConfig;

import lombok.extern.slf4j.Slf4j;

/**
 * @author shishun.wang
 * @date 2017年3月9日 上午11:56:45
 * @version 1.0
 * @describe
 */
@Slf4j
@Component
public class UserService {

	@Autowired
	private LocationConfig locationConfig;

	private static String MODEL_NAME = UserService.class.getName();

	private static String QUERY_USER_LIST = "/user/{0}/{1}";

	public PageInfo<UserVo> query(Integer pageNumber, Integer pageSize) {
		try {
			HttpResponse response = locationConfig.accredit(HttpClientFactory.GET.build(locationConfig.mgUri(QUERY_USER_LIST), pageNumber, pageSize))
					.execute();
			return ServerResponseParse.parse(HttpClientResponseParse.parseGeneric(response, new TypeReference<ServerResponse<PageInfo<UserVo>>>() {
			}));
		} catch (Exception e) {
			log.error(MODEL_NAME, e);
		}
		return PageInfo.empty();
	}

}
